home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1991-12-27 | 55.2 KB | 1,954 lines
Newsgroups: comp.sources.misc From: tcamp@hercules.acpub.duke.edu (Ted Campbell) Subject: v27i020: sfs - Space Flight Simulator, Part20/21 Message-ID: <1991Dec24.192021.21272@sparky.imd.sterling.com> X-Md4-Signature: 0244bac2db9285498be96ee343c681cc Date: Tue, 24 Dec 1991 19:20:21 GMT Approved: kent@sparky.imd.sterling.com Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell) Posting-number: Volume 27, Issue 20 Archive-name: sfs/part20 Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11 #!/bin/sh # do not concatenate these parts, unpack them in order with /bin/sh # file sfs/sfs/sfsm.h continued # if test ! -r _shar_seq_.tmp; then echo 'Please unpack part 1 first!' exit 1 fi (read Scheck if test "$Scheck" != 20; then echo Please unpack part "$Scheck" next! exit 1 else exit 0 fi ) < _shar_seq_.tmp || exit 1 if test ! -f _shar_wnt_.tmp; then echo 'x - still skipping sfs/sfs/sfsm.h' else echo 'x - continuing file sfs/sfs/sfsm.h' sed 's/^X//' << 'SHAR_EOF' >> 'sfs/sfs/sfsm.h' && #define STAT_TITLE "STATUS" #define SFSM_CPFI "The current program file is: %s; %s " #define SFSM_CPFX "Current Program File " #define MM_TTL " Main Menu " #define SFSM_SPF "Select SFS Program File" #define MEMERR_ERR "Cannot allocate memory for error message.\n" #define ERR_PROMPT "ERROR: %s; Do you want to continue? " #define ERRP_NO "N - ABORT" #define ERRP_YES "Y - Continue" #define ERR_MATH "Mathematics error, %s" #define OM_TITLE "Orbital Modeling Menu" #define SOP_TITLE "Set Orbital Parameters" #define AP_TITLE "Additional Parameters" #define OM_SPT " Set program title [%s] " #define OM_SON " Set current orbit Number [%d] " #define OM_SOP " Set orbital parameters" #define OM_SIP " Set insertion parameter [%ld seconds] " #define OM_SSP " Set system parameters" #define OM_VCO " View current orbit" #define OM_EXIT " Exit from modeling" #define OM_TTL "Orbital Modeling Menu" #define SPT_TITLE "Set Program Title" #define SPT_LEGEND "Please enter a new title for the program or RETURN to keep the old one." #define SPT_PROMPT "Program Title: " #define SON_TITLE "Set Current Orbit Number" #define SON_LEGEND "Enter an Orbit number between 1 and %d" #define SON_PROMPT "Number of Orbit: " #define SIP_TITLE "Set Insertion Point " #define SIP_LEGEND "The insertion point is the moment in the orbit when insertion occurs. Enter the insertion point in seconds." #define SIP_PROMPT "Insertion: " #define OM_SF "Please indicate whether you want to save the parameters you have entered. Enter Y or N" #define SF_TITLE "Set Filename to Save Parameters" #define SF_LEGEND "Please enter a filename for the new parameters to be saved, or enter <RETURN> to use the current name (old contents will be destroyed)." #define SF_PROMPT "Filename: " #define MM_MEMERR "Cannot allocate memory for Modeling Menu " #define OPM_MEMERR "Cannot allocate memory for Orbital Parameters Menu " #define APM_MEMERR "Cannot allocate memory for Auxiliary Parameters Menu " #define SPM_MEMERR "Cannot allocate memory for System Parameters Menu " #define SSP_TF " Time Factor [%ld x real time]" #define SSP_UI " Screen Update Interval [%ld seconds]" #define SSP_TPL " Trig Precision Level [%d]" #define SSP_EXIT " Exit to Main Orbital Modeling Menu" #define SSP_TITLE "Set System Parameters" #define SOP_SOF " Set orbital focus [%s] " #define SOP_SN " Name of Spacecraft/Orbit [%s]" #define SOP_SDF " Surface Datafile [%s]" #define SOP_PRI " Periapsis [%.2lf km]" #define SOP_APO " Apoapsis [%.2lf km]" #define SOP_INC " Inclination [%.2lf deg]" #define SOP_ARP " Argument of the Periapsis [%.2lf deg]" #define SOP_LAN " Longitude of Asc. Node [%.2lf deg]" #define SOP_EXIT " Exit to Main Orbital Modeling Menu" #define SOP_TITLE2 "Set Parameters for Orbit %d" #define SOF_TITLE "Select SFS Focal Data File" #define SN_TITLE "Set Orbit/Spacecraft Name for Orbit %d" #define SN_PROMPT "Name of Orbit/Spacecraft: " #define SN_LEGEND "Enter a name for the orbit or the spacecraft." #define SDF_TITLE "Select Surface Data File" #define PRI_TITLE "Set Periapsis for Orbit %d" #define PRI_LEGEND "The periapsis is the lowest point in an orbit. Enter the periapsis in kilometers (must be less than %.1lf km). " #define PRI_PROMPT "Periapsis: " #define APO_TITLE "Set Apoapsis for Orbit %d" #define APO_LEGEND "The apoapsis is the highest point in an orbit. Enter the apoapsis in kilometers (must be greater than %.1lf km). " #define APO_PROMPT "Apoapsis: " #define INC_TITLE "Set Inclination for Orbit %d" #define INC_LEGEND "The inclination describes the angle at which the orbit is inclined with relation to the equator of the orbital focus. Enter the inclination in degrees between %.1lf and %.1lf. " #define INC_PROMPT "Inclination: " #define ARP_TITLE "Set Argument of the Periapsis for Orbit %d" #define ARP_LEGEND "The argument of the periapsis describes the point in the orbit at which periapsis occurs, measured from the point of the ascending node. Enter the argument of the periapsis in degrees between %.1lf and %.1lf." #define ARP_PROMPT "Argument of Periapsis: " #define LAN_TITLE "Set the Longitude of the Ascending Node for Orbit %d" #define LAN_LEGEND "The longitude of the ascending node describes the point in the first orbit at which the spacecraft crosses the equator heading northward. Enter the longitude of the ascending node in degrees between %.1lf and %.1lf." #define LAN_PROMPT "Longitude of Ascending Node: " #define AP_MAS " Mass of the Orbital Focus [%.2le gr]" #define AP_RAD " Radius of the Orbital Focus [%.0lf km]" #define AP_SID " Sidereal Period [%.0lf seconds]" #define AP_SMI " Semiminor Axis [%.2lf km]" #define AP_ECC " Eccentricity [%.6lf]" #define AP_PER " Orbital Period [%.2lf seconds; %.2lf days]" #define AP_TITLE2 "Additional Parameters for Orbit %d" #define GETYN_NO " NO " #define GETYN_YES " YES " #define SPW_MEMERR "Cannot allocate memory for set parameters window " #define MES_MM "Main Menu" #define MES_OM "Orbital Modeling Menu" #define MES_SP "Set Parameters Menu" #define MES_SSP "Set System Parameters Menu" #endif X extern double get_double(); extern long get_long(); X extern char init_buffer[ 128 ]; /* Buffer for initialization X of focal data */ extern char sfs_tbuf[ 512 ]; X extern int sfs_curorbit; extern long sfs_insertion; extern long sfs_inc; extern long sfs_tfactor; /* time factor */ extern char sfs_prname[ 128 ]; extern int sfs_go; extern double sfs_size; /* size factor for particular screen */ extern double sin_table[ 91 ]; X extern int display; extern int _xy_array[ 20 ]; extern int work_in[ 21 ]; extern int work_out[ 57 ]; extern char sfs_program[ 36 ]; extern struct uiwindow *set_window; extern struct menu_box w1, w2, w3, w4; extern int sp_x1, sp_y1, sp_x2, sp_y2; extern struct dir_ent *d_entries[ MAX_ENTRIES ]; extern char *d_titles[ MAX_ENTRIES ]; X X /*** Colors */ X extern int cl_mback; /* Main background color */ extern int cl_mfore; /* Main foreground color */ extern int cl_marker; /* Color for prompt markers */ extern int cl_grid; /* Color for planetary grid */ extern int cl_surface; /* Color for planetary surface */ extern int cl_orbits[ 6 ]; /* Colors for different orbits */ X extern struct uiwindow *main_window; /* structure for main window */ extern struct uiwindow *logo_window; X extern int stat_y1; /* line for status display */ extern int stat_y2; /* top of status display */ extern int stat_x1; /* column for status display */ extern int stat_x2; /* max col for status display */ X SHAR_EOF echo 'File sfs/sfs/sfsm.h is complete' && chmod 0644 sfs/sfs/sfsm.h || echo 'restore of sfs/sfs/sfsm.h failed' Wc_c="`wc -c < 'sfs/sfs/sfsm.h'`" test 10462 -eq "$Wc_c" || echo 'sfs/sfs/sfsm.h: original size 10462, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= sfs/sfs/sfsm.mak ============== if test -f 'sfs/sfs/sfsm.mak' -a X"$1" != X"-c"; then echo 'x - skipping sfs/sfs/sfsm.mak (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting sfs/sfs/sfsm.mak (Text)' sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm.mak' && PROJ =SFSM DEBUG =0 CC =qcl CFLAGS_G = /AL /W1 /Ze /DDEBUG /I..\..\include CFLAGS_D = /Zi /Zr /Gi$(PROJ).mdt /Od CFLAGS_R = /O /Ot /DNDEBUG CFLAGS =$(CFLAGS_G) $(CFLAGS_R) LFLAGS_G = /CP:0xffff /NOI /NOE /SE:0x80 /ST:0x800 LFLAGS_D = /CO /M /INCR LFLAGS_R = LFLAGS =$(LFLAGS_G) $(LFLAGS_R) RUNFLAGS = OBJS_EXT = ..\..\lib\dr_ibmpc.obj ..\..\lib\gr_ibmpc.obj ..\..\lib\kb_ibmpc.obj ..\..\lib\ui_boxes.obj \ X ..\..\lib\ui_dial.obj ..\..\lib\ui_gets.obj ..\..\lib\ui_init.obj ..\..\lib\ui_list.obj \ X ..\..\lib\ui_text.obj ..\..\lib\ui_pbm.obj LIBS_EXT = X all: $(PROJ).exe X sfsm_om.obj: sfsm_om.c X sfsm.obj: sfsm.c X as_orbit.obj: ..\as\as_orbit.c X as_spj.obj: ..\as\as_spj.c X as_vpt.obj: ..\as\as_vpt.c X sfs_pe.obj: sfs_pe.c X sfs_pr.obj: sfs_pr.c X as_focus.obj: ..\as\as_focus.c X $(PROJ).exe: sfsm_om.obj sfsm.obj as_orbit.obj as_spj.obj as_vpt.obj sfs_pe.obj sfs_pr.obj \ X as_focus.obj $(OBJS_EXT) X echo >NUL @<<$(PROJ).crf sfsm_om.obj + sfsm.obj + as_orbit.obj + as_spj.obj + as_vpt.obj + sfs_pe.obj + sfs_pr.obj + as_focus.obj + $(OBJS_EXT) $(PROJ).exe X $(LIBS_EXT); << X link $(LFLAGS) @$(PROJ).crf X run: $(PROJ).exe X $(PROJ) $(RUNFLAGS) X SHAR_EOF chmod 0644 sfs/sfs/sfsm.mak || echo 'restore of sfs/sfs/sfsm.mak failed' Wc_c="`wc -c < 'sfs/sfs/sfsm.mak'`" test 1158 -eq "$Wc_c" || echo 'sfs/sfs/sfsm.mak: original size 1158, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= sfs/sfs/sfsm_n.mak ============== if test -f 'sfs/sfs/sfsm_n.mak' -a X"$1" != X"-c"; then echo 'x - skipping sfs/sfs/sfsm_n.mak (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting sfs/sfs/sfsm_n.mak (Text)' sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm_n.mak' && PROJ =SFSM DEBUG =0 LIBDIR = ..\..\lib CC =qcl CFLAGS_G = /AL /W1 /Ze /DDEBUG /I..\..\include CFLAGS_D = /Zi /Zr /Gi$(PROJ).mdt /Od CFLAGS_R = /O /Ot /DNDEBUG CFLAGS =$(CFLAGS_G) $(CFLAGS_R) LFLAGS_G = /CP:0xffff /NOI /NOE /SE:0x80 /ST:0x800 LFLAGS_D = /CO /M /INCR LFLAGS_R = LFLAGS =$(LFLAGS_G) $(LFLAGS_R) RUNFLAGS = OBJS_A = $(LIBDIR)\dr_ibmpc.obj $(LIBDIR)\gr_ibmpc.obj $(LIBDIR)\kb_ibmpc.obj $(LIBDIR)\ui_boxes.obj OBJS_B = $(LIBDIR)\ui_dial.obj $(LIBDIR)\ui_gets.obj $(LIBDIR)\ui_init.obj OBJS_C = $(LIBDIR)\ui_list.obj $(LIBDIR)\ui_text.obj $(LIBDIR)\ui_pbm.obj LIBS_EXT = X all: $(PROJ).exe X sfsm_om.obj: sfsm_om.c X sfsm.obj: sfsm.c X sfs_pe.obj: sfs_pe.c X sfs_pr.obj: sfs_pr.c X as_orbit.obj: X $(CC) $(CFLAGS) -c ..\as\as_orbit.c X as_spj.obj: X $(CC) $(CFLAGS) -c ..\as\as_spj.c X as_vpt.obj: X $(CC) $(CFLAGS) -c ..\as\as_vpt.c X as_focus.obj: X $(CC) $(CFLAGS) -c ..\as\as_focus.c X $(PROJ).exe: sfsm_om.obj sfsm.obj as_orbit.obj as_spj.obj \ X as_vpt.obj sfs_pe.obj sfs_pr.obj \ X as_focus.obj \ X $(OBJS_A) \ X $(OBJS_B) \ X $(OBJS_C) X echo >NUL @<<$(PROJ).crf sfsm_om.obj + sfsm.obj + as_orbit.obj + as_spj.obj + as_vpt.obj + sfs_pe.obj + sfs_pr.obj + as_focus.obj + $(OBJS_A) + $(OBJS_B) + $(OBJS_C) $(PROJ).exe X $(LIBS_EXT); << X link $(LFLAGS) @$(PROJ).crf X run: $(PROJ).exe X $(PROJ) $(RUNFLAGS) X SHAR_EOF chmod 0644 sfs/sfs/sfsm_n.mak || echo 'restore of sfs/sfs/sfsm_n.mak failed' Wc_c="`wc -c < 'sfs/sfs/sfsm_n.mak'`" test 1443 -eq "$Wc_c" || echo 'sfs/sfs/sfsm_n.mak: original size 1443, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= sfs/sfs/sfsm_om.c ============== if test -f 'sfs/sfs/sfsm_om.c' -a X"$1" != X"-c"; then echo 'x - skipping sfs/sfs/sfsm_om.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting sfs/sfs/sfsm_om.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsm_om.c' && /*************************************************************** X X sfsm_om.c Orbital Modeling routines for X Space Flight Simulator, X Modeling Module X X Copyright (c) 1991, Ted A. Campbell X X Bywater Software X P. O. Box 4023 X Duke Station X Durham, NC 27706 X X email: tcamp@hercules.acpub.duke.edu X X Copyright and Permissions Information: X X All U.S. and international copyrights are claimed by the X author. The author grants permission to use this code X and software based on it under the following conditions: X (a) in general, the code and software based upon it may be X used by individuals and by non-profit organizations; (b) it X may also be utilized by governmental agencies in any country, X with the exception of military agencies; (c) the code and/or X software based upon it may not be sold for a profit without X an explicit and specific permission from the author, except X that a minimal fee may be charged for media on which it is X copied, and for copying and handling; (d) the code must be X distributed in the form in which it has been released by the X author; and (e) the code and software based upon it may not X be used for illegal activities. X ***************************************************************/ X #include "stdio.h" #include "sfsm.h" X #ifdef __STDC__ #include "malloc.h" #else extern char * malloc(); #endif X #ifndef __STDC__ #define time_t long #define size_t int #endif X #define OM_TITLES 7 #define SP_TITLES 9 #define AP_TITLES 6 #define SYS_TITLES 4 X extern struct as_focus * pr_getfd(); X struct uiwindow *set_window; int sp_x1, sp_y1, sp_x2, sp_y2; int sp_ready; X static int spmem; X static char *om_titles[ OM_TITLES ]; static char *sp_titles[ SP_TITLES ]; static char *ap_titles[ AP_TITLES ]; static char *sys_titles[ SYS_TITLES ]; static char t_buffer[ BW_EBUFSIZE ]; static char set_buffer[ 64 ]; static struct sfs_orbit *ap_oldorbit = NULL; X extern int null_poll(); X sfs_om( sorbit_array, n_orbits ) X struct sfs_orbit **sorbit_array; X int n_orbits; X { X int orbit, keep_on, item, c; X long l; X static int x_elements = VI_ORBOUTLINE | VI_GRIDFRONT | VI_SURFRONT; X X ui_fbox( main_window->u_x1, main_window->u_y1, X main_window->u_x2, main_window->u_y2, BLACK, SOLID ); X X if ( sp_ready == 0 ) X { X sp_init(); X sp_ready = 1; X } X X tl_window( OM_TITLE ); X tr_window( SOP_TITLE ); X bl_window( SFSM_PEBL ); X br_window( AP_TITLE ); X w1.is_drawn = FALSE; X w2.is_drawn = FALSE; X ap_oldorbit = NULL; X sfsm_sp( FALSE, sorbit_array, sfs_curorbit, n_orbits ); X X keep_on = TRUE; X while ( keep_on == TRUE ) X { X #ifdef BLOCKEDOUT X pe_calc( sorbit_array, n_orbits ); X pe_draw( w3.window, sorbit_array[ sfs_curorbit ]->aorbit->focus, X sorbit_array, n_orbits, NULL, NULL, (long) 0, x_elements ); #endif X X bw_message( MES_OM ); X X pr_stripcr( sfs_prname ); X sprintf( om_titles[ 0 ], OM_SPT, sfs_prname ); X sprintf( om_titles[ 1 ], OM_SON, sfs_curorbit + 1 ); X strcpy( om_titles[ 2 ], OM_SOP ); X sprintf( om_titles[ 3 ], OM_SIP, sfs_insertion ); X strcpy( om_titles[ 4 ], OM_SSP ); X strcpy( om_titles[ 5 ], OM_VCO ); X strcpy( om_titles[ 6 ], OM_EXIT ); X X item = ui_list( MENU_TITLED, w1.window->x1, w1.window->y1, X w1.window->x2, w1.window->y2, X OM_TTL, X OM_TITLES, om_titles, cl_mfore, cl_mback, X cl_marker, &w1 ); X X switch( item ) X { X case 0: X get_string( SPT_TITLE, SPT_LEGEND, SPT_PROMPT, X sfs_prname ); X sprintf( om_titles[ 0 ], OM_SPT, sfs_prname ); X w1.is_drawn = FALSE; X break; X case 1: X sprintf( sfs_tbuf, SON_LEGEND, ORBITS ); X sfs_curorbit = get_int( SON_TITLE, X sfs_tbuf, SON_PROMPT, X sfs_curorbit, 1, ORBITS ) - 1; X if ( sorbit_array[ sfs_curorbit ] == NULL ) X { X pr_default( sorbit_array, sfs_curorbit, n_orbits, DEFAULTFD ); X } X sprintf( om_titles[ 1 ], X OM_SON, sfs_curorbit + 1 ); X sfsm_sp( FALSE, sorbit_array, sfs_curorbit, n_orbits ); X w1.is_drawn = FALSE; X w2.is_drawn = FALSE; X break; X case 2: X w2.is_drawn = FALSE; X sfsm_sp( TRUE, sorbit_array, sfs_curorbit, n_orbits ); X break; X case 3: X sfs_insertion = get_long( SIP_TITLE, X SIP_LEGEND, SIP_PROMPT, X (long) sfs_insertion, X (long) 0, X (long) sorbit_array[ sfs_curorbit ]->aorbit->period ); X sprintf( om_titles[ 3 ], X OM_SIP, sfs_insertion ); X w1.is_drawn = FALSE; X break; X case 4: X w2.is_drawn = FALSE; X sfs_sysp(); X break; X case 5: X pe_calc( sorbit_array, n_orbits, null_poll ); X pe_draw( w3.window, sorbit_array[ sfs_curorbit ]->aorbit->focus, X sorbit_array, n_orbits, NULL, NULL, (long) 0, x_elements ); X break; X case TK_EXIT: X case 6: X keep_on = FALSE; X c = get_yn( OM_SF ); X if ( c == TRUE ) X { X get_string( SF_TITLE, X SF_LEGEND, X SF_PROMPT, X sfs_program ); X pr_save( sfs_program, sorbit_array, n_orbits, sfs_prname ); X } X w1.is_drawn = FALSE; X break; X } X } X } X sp_init() X { X int height, length, midx, midy, c; X X midx = main_window->u_x1 + ( ( main_window->u_x2 - main_window->u_x1 ) / 2 ); X midy = main_window->u_y1 + ( ( main_window->u_y2 - main_window->u_y1 ) / 2 ); X X length = ( main_window->u_x2 * 3 ) / 5; X sp_x1 = midx - length / 2; X sp_x2 = midx + length / 2; X height = main_window->u_y2 / 2; X sp_y1 = midy - height / 2; X sp_y2 = midy + height / 2; X X for ( c = 0; c < OM_TITLES; ++c ) X { X if ( ( om_titles[ c ] = malloc( 64 ) ) == NULL ) X { X bw_error( MM_MEMERR ); X } X } X for ( c = 0; c < SP_TITLES; ++c ) X { X if ( ( sp_titles[ c ] = malloc( 64 ) ) == NULL) X { X bw_error( OPM_MEMERR ); X } X } X for ( c = 0; c < AP_TITLES; ++c ) X { X if ( ( ap_titles[ c ] = malloc( 64 ) ) == NULL) X { X bw_error( APM_MEMERR ); X } X } X for ( c = 0; c < SYS_TITLES; ++c ) X { X if ( ( sys_titles[ c ] = malloc( 64 ) ) == NULL) X { X bw_error( SPM_MEMERR ); X } X } X X } X sfs_sysp() X { X int c, y, item; X X /* set up titles for menu */ X X sprintf( sys_titles[ 0 ], SSP_TF, X (long) sfs_tfactor ); X sprintf( sys_titles[ 1 ], SSP_UI, X (long) sfs_inc ); X sprintf( sys_titles[ 2 ], SSP_TPL, X vpt_level ); X sprintf( sys_titles[ 3 ], SSP_EXIT ); X w2.is_drawn = FALSE; X X bw_message( MES_SSP ); X X y = TRUE; X while( y == TRUE ) X { X X item = ui_list( MENU_TITLED, w2.window->x1, w2.window->y1, X w2.window->x2, w2.window->y2, X SSP_TITLE, X SYS_TITLES, sys_titles, X cl_mfore, cl_mback, X cl_marker, &w2 ); X X /* Process the argument */ X X switch( item ) X { X case 0: X sfs_tfactor = get_long( TF_TITLE, X TF_LEGEND, X TF_PROMPT, X (long) sfs_tfactor, X (long) 1, (long) 0 ); X sprintf( sys_titles[ 0 ], SSP_TF, X (long) sfs_tfactor ); X w2.is_drawn = FALSE; X break; X case 1: X sfs_inc = get_long( UI_TITLE, X UI_LEGEND, X UI_PROMPT, X (long) sfs_inc, X (long) 1, (long) 0 ); X sprintf( sys_titles[ 1 ], SSP_UI, X (long) sfs_inc ); X w2.is_drawn = FALSE; X break; X case 2: X vpt_level = get_int( TPL_TITLE, X TPL_LEGEND, X TPL_PROMPT, X vpt_level, 1, 2 ); X sprintf( sys_titles[ 2 ], SSP_TPL, X vpt_level ); X w2.is_drawn = FALSE; X break; X case TK_EXIT: X case 3: X y = FALSE; X break; X } X X } X } X /*************************************************************** X X sfsm_sp() set orbital parameters X ***************************************************************/ X sfsm_sp( execute, sorbit_array, orbit_n, n_orbits ) X int execute; X struct sfs_orbit **sorbit_array; X int orbit_n, n_orbits; X { X register int c; X int item, y; X static char x_buffer[ BW_EBUFSIZE ]; X static struct menu_box fs_box; X X if ( execute == TRUE ) X { X bw_message( MES_SP ); X } X X y = TRUE; X while( y == TRUE ) X { X X if ( sorbit_array[ orbit_n ] != ap_oldorbit ) X { X or_init( sorbit_array[ sfs_curorbit ]->aorbit, X sorbit_array[ sfs_curorbit ]->aorbit->periapsis, X sorbit_array[ sfs_curorbit ]->aorbit->apoapsis ); X X sfs_ap( sorbit_array, sfs_curorbit ); X ap_oldorbit = sorbit_array[ orbit_n ]; X X /* set up titles for menu */ X X sprintf( sp_titles[ 0 ], SOP_SOF, X sorbit_array[ sfs_curorbit ]->aorbit->focus->fdfile ); X sprintf( sp_titles[ 1 ], SOP_SN, X sorbit_array[ sfs_curorbit ]->name ); X sprintf( sp_titles[ 2 ], SOP_SDF, X sorbit_array[ sfs_curorbit ]->surfile ); X sprintf( sp_titles[ 3 ], SOP_PRI, X sorbit_array[ sfs_curorbit ]->aorbit->periapsis ); X sprintf( sp_titles[ 4 ], SOP_APO, X sorbit_array[ sfs_curorbit ]->aorbit->apoapsis ); X sprintf( sp_titles[ 5 ], SOP_INC, X sorbit_array[ sfs_curorbit ]->aorbit->inclination ); X sprintf( sp_titles[ 6 ], SOP_ARP, X sorbit_array[ sfs_curorbit ]->aorbit->arg_per ); X sprintf( sp_titles[ 7 ], SOP_LAN, X sorbit_array[ sfs_curorbit ]->aorbit->lon_an ); X strcpy( sp_titles[ 8 ], SOP_EXIT ); X X tr_window( x_buffer ); X w2.is_drawn = FALSE; X } X X sprintf( x_buffer, SOP_TITLE2, sfs_curorbit + 1 ); X X if ( execute == FALSE ) X { X uil_draw( MENU_TITLED, w2.window->x1, w2.window->y1, X w2.window->x2, w2.window->y2, X x_buffer, SP_TITLES, sp_titles, X cl_mfore, cl_mback, cl_marker, &w2 ); X X return TRUE; X } X X item = ui_list( MENU_TITLED, w2.window->x1, w2.window->y1, X w2.window->x2, w2.window->y2, X x_buffer, SP_TITLES, sp_titles, X cl_mfore, cl_mback, cl_marker, &w2 ); X X /* Process the argument */ X X switch( item ) X { X case 0: X sfsm_getspw(); X fs_box.is_drawn = FALSE; X item = ui_ftext( sp_x1, sp_y1, sp_x2, sp_y2, "*.fd", X SOF_TITLE, X &fs_box, d_titles, d_entries, MAX_ENTRIES, X cl_mback, cl_mfore, cl_marker ); X fntolc( d_titles[ item ] ); X X sorbit_array[ sfs_curorbit ]->aorbit->focus X = pr_getfd( sorbit_array, sfs_curorbit, n_orbits, X d_titles[ item ] ); X sprintf( sp_titles[ 0 ], SOP_SOF, X sorbit_array[ sfs_curorbit ]->aorbit->focus->fdfile ); X sfsm_putspw(); X w2.is_drawn = FALSE; X break; X X case 1: X sprintf( t_buffer, SN_TITLE, sfs_curorbit + 1); X get_string( set_buffer, SN_LEGEND, X SN_PROMPT, sfs_tbuf ); X strcpy( sorbit_array[ sfs_curorbit ]->name, sfs_tbuf ); X sprintf( sp_titles[ 1 ], SOP_SN, X sorbit_array[ sfs_curorbit ]->name ); X w2.is_drawn = FALSE; X break; X X case 2: X sfsm_getspw(); X fs_box.is_drawn = FALSE; X item = ui_ftext( sp_x1, sp_y1, sp_x2, sp_y2, "*.spd", X SDF_TITLE, X &fs_box, d_titles, d_entries, MAX_ENTRIES, X cl_mback, cl_mfore, cl_marker ); X fntolc( d_titles[ item ] ); X strncpy( sorbit_array[ sfs_curorbit ]->surfile, X d_titles[ item ], SFS_FILESIZE - 2 ); X sprintf( sp_titles[ 2 ], SOP_SDF, X sorbit_array[ sfs_curorbit ]->surfile ); X sfsm_putspw(); X w2.is_drawn = FALSE; X break; X X case 3: X sprintf( t_buffer, PRI_TITLE, sfs_curorbit + 1 ); X sprintf( sfs_tbuf, PRI_LEGEND, X (double) sorbit_array[ sfs_curorbit ]->aorbit->apoapsis ); X sorbit_array[ sfs_curorbit ]->aorbit->periapsis = get_double( t_buffer, X sfs_tbuf, X PRI_PROMPT, X (double) sorbit_array[ sfs_curorbit ]->aorbit->periapsis, X (double) 0.0, X (double) sorbit_array[ sfs_curorbit ]->aorbit->apoapsis ); X sfsm_clpe(); X sprintf( sp_titles[ 3 ], SOP_PRI, X sorbit_array[ sfs_curorbit ]->aorbit->periapsis ); X w2.is_drawn = FALSE; X break; X X case 4: X sprintf( t_buffer, APO_TITLE, sfs_curorbit + 1 ); X sprintf( sfs_tbuf, APO_LEGEND, X (double) sorbit_array[ sfs_curorbit ]->aorbit->periapsis ); X sorbit_array[ sfs_curorbit ]->aorbit->apoapsis = get_double( t_buffer, X sfs_tbuf, X APO_PROMPT, X (double) sorbit_array[ sfs_curorbit ]->aorbit->apoapsis, X (double) sorbit_array[ sfs_curorbit ]->aorbit->periapsis, X (double) 0.0 ); X sfsm_clpe(); X sprintf( sp_titles[ 4 ], SOP_APO, X sorbit_array[ sfs_curorbit ]->aorbit->apoapsis ); X w2.is_drawn = FALSE; X break; X case 5: X sprintf( t_buffer, INC_TITLE, sfs_curorbit + 1); X sprintf( sfs_tbuf, INC_LEGEND, X (double) OR_INC_MIN, (double) OR_INC_MAX ); X sorbit_array[ sfs_curorbit ]->aorbit->inclination = get_double( t_buffer, X sfs_tbuf, X INC_PROMPT, X sorbit_array[ sfs_curorbit ]->aorbit->inclination, X (double) OR_INC_MIN, (double) OR_INC_MAX ); X sfsm_clpe(); X X /*** inclination cannot be 90 or -90 ***/ X X if ( sorbit_array[ sfs_curorbit ]->aorbit->inclination == 90.0 ) X { X sorbit_array[ sfs_curorbit ]->aorbit->inclination = 89.9999; X } X if ( sorbit_array[ sfs_curorbit ]->aorbit->inclination == -90.0 ) X { X sorbit_array[ sfs_curorbit ]->aorbit->inclination = -89.9999; X } X X sprintf( sp_titles[ 5 ], SOP_INC, X sorbit_array[ sfs_curorbit ]->aorbit->inclination ); X w2.is_drawn = FALSE; X break; X case 6: X sprintf( t_buffer, ARP_TITLE, sfs_curorbit + 1 ); X sprintf( sfs_tbuf, ARP_LEGEND, X (double) OR_ARP_MIN, (double) OR_ARP_MAX ); X sorbit_array[ sfs_curorbit ]->aorbit->arg_per = get_double( t_buffer, X sfs_tbuf, X ARP_PROMPT, X sorbit_array[ sfs_curorbit ]->aorbit->arg_per, X (double) OR_ARP_MIN, (double) OR_ARP_MAX ); X sfsm_clpe(); X sprintf( sp_titles[ 6 ], SOP_ARP, X sorbit_array[ sfs_curorbit ]->aorbit->arg_per ); X w2.is_drawn = FALSE; X break; X case 7: X sprintf( t_buffer, LAN_TITLE, sfs_curorbit +1 ); X sprintf( sfs_tbuf, LAN_LEGEND, X OR_LAN_MIN, OR_LAN_MAX ); X sorbit_array[ sfs_curorbit ]->aorbit->lon_an = get_double( t_buffer, X sfs_tbuf, X LAN_PROMPT, X sorbit_array[ sfs_curorbit ]->aorbit->lon_an, X (double) OR_LAN_MIN, (double) OR_LAN_MAX ); X sfsm_clpe(); X sprintf( sp_titles[ 7 ], SOP_LAN, X sorbit_array[ sfs_curorbit ]->aorbit->lon_an ); X w2.is_drawn = FALSE; X break; X case TK_EXIT: X case 8: X y = 0; X break; X } X X if ( w2.is_drawn == FALSE ) X { X or_init( sorbit_array[ sfs_curorbit ]->aorbit, X sorbit_array[ sfs_curorbit ]->aorbit->periapsis, X sorbit_array[ sfs_curorbit ]->aorbit->apoapsis ); X sfs_ap( sorbit_array, sfs_curorbit ); X } X } X } X sfs_ap( sorbit_array, orbit_n ) X struct sfs_orbit **sorbit_array; X int orbit_n; X { X static char x_buffer[ BW_EBUFSIZE ]; X X /* set up titles for menu */ X X sprintf( ap_titles[ 0 ], AP_MAS, X sorbit_array[ orbit_n ]->aorbit->focus->mass ); X sprintf( ap_titles[ 1 ], AP_RAD, X sorbit_array[ orbit_n ]->aorbit->focus->radius ); X sprintf( ap_titles[ 2 ], AP_SID, X sorbit_array[ orbit_n ]->aorbit->focus->sid_day ); X sprintf( ap_titles[ 3 ], AP_SMI, X sorbit_array[ sfs_curorbit ]->aorbit->semiminor ); X sprintf( ap_titles[ 4 ], AP_ECC, X sorbit_array[ sfs_curorbit ]->aorbit->eccentricity ); X sprintf( ap_titles[ 5 ], AP_PER, X sorbit_array[ sfs_curorbit ]->aorbit->period, X sorbit_array[ sfs_curorbit ]->aorbit->period / (double) 86400 ); X X sprintf( x_buffer, AP_TITLE2, orbit_n + 1 ); X X br_window( t_buffer ); X w4.is_drawn = FALSE; X uil_draw( MENU_TITLED, w4.window->x1, w4.window->y1, X w4.window->x2, w4.window->y2, X x_buffer, AP_TITLES, ap_titles, X cl_mfore, cl_mback, cl_marker, &w4 ); X X X } X get_yn( text ) X char *text; X { X register int c; X static struct uiwindow *yn_window; X X sfsm_getspw(); X X c = ui_yn( sp_x1, sp_y1, sp_x2, sp_y2, X cl_mback, cl_mfore, cl_marker, TRUE, X text, GETYN_NO, GETYN_YES, &yn_window ); X X sfsm_putspw(); X return c; X } X get_string( title, text, prompt, buffer ) X char *title, *text, *prompt, *buffer; X { X sfsm_getspw(); X X get_window(); X ui_dial( sp_x1, sp_y1, sp_x2, sp_y2, cl_mback, cl_mfore, cl_marker, X 1, title, X text, prompt, set_buffer, &set_window ); X if ( set_buffer[ 0 ] != 0 ) X { X strcpy( buffer, set_buffer ); X } X X sfsm_putspw(); X } X get_int( title, text, prompt, oldvalue, minimum, maximum ) X char *title, *text, *prompt; X int oldvalue, minimum, maximum; X { X char *_text; X int y; X static int n; X X sfsm_getspw(); X X _text = text; X y = 1; X while( y == 1 ) X { X get_window(); X ui_dial( sp_x1, sp_y1, sp_x2, sp_y2, cl_mback, cl_mfore, X cl_marker, 1, title, X _text, prompt, set_buffer, &set_window ); X if ( set_buffer[ 0 ] == 0 ) X { X sfsm_putspw(); X return oldvalue; X } X X sscanf( set_buffer, "%d", &n ); X y = 0; X if ( n < minimum ) X { X sprintf( sfs_tbuf, "%s %ld; %s.", MINERR, minimum - 1, PTA ); X _text = sfs_tbuf; X y = 1; X } X if ( ( maximum != 0 ) && ( n > maximum )) X { X y = 1; X sprintf( sfs_tbuf, "%s %ld; %s.", MAXERR, maximum + 1, PTA ); X _text = sfs_tbuf; X } X } X X sfsm_putspw(); X return n; X } X long get_long( title, text, prompt, oldvalue, minimum, maximum ) X char *title, *text, *prompt; X long oldvalue, minimum, maximum; X { X char *_text; X int y; X static long n; X X sfsm_getspw(); /* save the set param window */ X X _text = text; X y = TRUE; X while( y == TRUE ) X { X get_window(); X ui_dial( sp_x1, sp_y1, sp_x2, sp_y2, cl_mback, cl_mfore, X cl_marker, 1, title, X _text, prompt, set_buffer, &set_window ); X X if ( set_buffer[ 0 ] == 0 ) X { X sfsm_putspw(); X return oldvalue; X } X X sscanf( set_buffer, "%ld", &n ); X y = 0; X if ( n < minimum ) X { X sprintf( sfs_tbuf, "%s %ld; %s.", MINERR, minimum - 1, PTA ); X _text = sfs_tbuf; X y = 1; X } X if ( ( maximum != 0 ) && ( n > maximum )) X { X y = 1; X sprintf( sfs_tbuf, "%s %ld; %s.", MAXERR, maximum + 1, PTA ); X _text = sfs_tbuf; X } X } X X sfsm_putspw(); X return n; X } X double get_double( title, text, prompt, oldvalue, minimum, maximum ) X char *title, *text, *prompt; X double oldvalue, minimum, maximum; X { X char *_text; X int y; X static double n; X X sfsm_getspw(); X X _text = text; X y = 1; X while( y == 1 ) X { X get_window(); X ui_dial( sp_x1, sp_y1, sp_x2, sp_y2, cl_mback, cl_mfore, X cl_marker, 1, title, X _text, prompt, set_buffer, &set_window ); X X if ( set_buffer[ 0 ] == 0 ) X { X sfsm_putspw(); X return oldvalue; X } X X sscanf( set_buffer, "%lf", &n ); X y = 0; X if ( n < minimum ) X { X sprintf( sfs_tbuf, "%s %.2lf; %s.", MINERR, minimum - 1, PTA ); X _text = sfs_tbuf; X y = 1; X } X if ( ( maximum != 0.0 ) && ( n > maximum )) X { X y = 1; X sprintf( sfs_tbuf, "%s %.2lf; %s.", MAXERR, maximum + 1, PTA ); X _text = sfs_tbuf; X } X } X X sfsm_putspw(); X return n; X } X /*************************************************************** X X get_window() This function is called prior to ui_dial X in get_xxx() functions in order to set X the title bar background color to cl_marker. X Since ui_dial does not allow specification X of a title bar color, this will set it, and X once set it will remian the same. X ***************************************************************/ X get_window() X { X if ( set_window == NULL ) X { X set_window = ui_window( sp_x1, sp_y1, sp_x2, sp_y2, TRUE, cl_marker, X BLACK, "", TRUE, cl_mfore, TRUE, BLACK, cl_mback, SOLID, FALSE ); X } X } X sfsm_clpe() X { X if ( w3.window == NULL ) X { X return BW_ERROR; X } X ui_fbox( w3.window->u_x1, w3.window->u_y1, X w3.window->u_x2, w3.window->u_y2, BLACK, SOLID ); X ui_fbox( w3.window->u_x1, w3.window->u_y1, X w3.window->u_x2, w3.window->u_y2, /* cl_mback */ WHITE, GRID ); X ui_rewindow( w3.window, SFSM_PEBL ); X X } X sfsm_getspw() X { X size_t x_size; X X gr_imsave( GR_PRIMARY, TRUE, sp_x1, sp_y1, sp_x2, sp_y2, &spmem ); X } X sfsm_putspw() X { X gr_imsave( GR_PRIMARY, FALSE, sp_x1, sp_y1, sp_x2, sp_y2, &spmem ); X gr_imfree( spmem ); X } X null_poll() X { X } SHAR_EOF chmod 0644 sfs/sfs/sfsm_om.c || echo 'restore of sfs/sfs/sfsm_om.c failed' Wc_c="`wc -c < 'sfs/sfs/sfsm_om.c'`" test 20737 -eq "$Wc_c" || echo 'sfs/sfs/sfsm_om.c: original size 20737, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= sfs/sfs/sfsx.c ============== if test -f 'sfs/sfs/sfsx.c' -a X"$1" != X"-c"; then echo 'x - skipping sfs/sfs/sfsx.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting sfs/sfs/sfsx.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfsx.c' && /*************************************************************** X X sfsx.c Space Flight Simulator X Orbital Simulation Module -- Main Segment X X Copyright (c) 1991, Ted A. Campbell X X Bywater Software X P. O. Box 4023 X Duke Station X Durham, NC 27706 X X email: tcamp@hercules.acpub.duke.edu X X Copyright and Permissions Information: X X All U.S. and international copyrights are claimed by the X author. The author grants permission to use this code X and software based on it under the following conditions: X (a) in general, the code and software based upon it may be X used by individuals and by non-profit organizations; (b) it X may also be utilized by governmental agencies in any country, X with the exception of military agencies; (c) the code and/or X software based upon it may not be sold for a profit without X an explicit and specific permission from the author, except X that a minimal fee may be charged for media on which it is X copied, and for copying and handling; (d) the code must be X distributed in the form in which it has been released by the X author; and (e) the code and software based upon it may not X be used for illegal activities. X ***************************************************************/ X /*** Include Files */ X #include "stdio.h" #include "signal.h" #include "time.h" #include "math.h" #include "sfsx.h" X #ifdef __STDC__ #include "malloc.h" #include "process.h" #else extern char * malloc(); #define size_t int #define time_t long #endif X /*** Local Data */ X int fo_xcenter, fo_ycenter; X static char *em_titles[ EM_TITLES ]; static FILE *data; static int x_zoom = FALSE; /* boolean: use zoom display? */ static int d_zoom; /* zoom window display */ static int d_upper; /* upper window display */ static int d_lower; /* lower window display */ struct uiwindow *e_wind; /* window for elements */ static x_init = FALSE; /* is video system initialized? */ static int *x_elements; /* pointer to elements to toggle */ static struct sfs_display **x_displays; static int n_displays = 0; /* number of displays */ static char **t_array; /* title array */ static char pr_file[ SFS_FILESIZE ]; X extern int sfsx_sigint(); extern int *sfsx_curel(); extern int sfsx_poll(); X /**************************************************************** X X main() Main Program Function X ****************************************************************/ X main( argc, argv ) X int argc; X char **argv; X { X int x_resume; /* resume execution? */ X X /*** First some precautionary measures */ X /*** Load "chain" so that the loader (sfs) will exit */ X /*** in the case of any unexpected exit */ X X if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != NULL ) X { X fprintf( data, "%s \n", SFSCH_EXIT ); X fclose( data ); X } X X /*** Now set a signal handler so that a SIGINT */ X /*** (control-C under DOS, DEL under Unix) will */ X /*** exit gracefully */ X X signal( SIGINT, sfsx_sigint ); X X /*** Set up initial program file */ X X if ( argc > 1 ) X { X strcpy( pr_file, argv[ 1 ] ); X } X else X { X strcpy( pr_file, SFS_DEFAULTPROG ); X } X X /*** Initialize Bywater user interface */ X X ui_init(); X X /* Return if initialization failed */ X X if ( ui_grwind->initialized == FALSE ) X { X fprintf( stderr, "Graphics system is not initialized.\n" ); X return -1; X } X #ifdef OLD_DEBUG X fprintf( stderr, "ui is now initialized\n" ); #endif X X /*** Initialize colors */ X X sfsx_colors(); X X /* reset icon colors */ X X if ( gr_colors > 2 ) X { X ui_seticons( cl_mback, cl_marker ); X } X X /*** Initialize parameters */ X X vpt_init(); X vpt_level = 1; X sfsx_font( 0 ); X X /*** Set up the screen */ X X sfsx_screen(); X X fo_xcenter = fo_window->x1 + (( fo_window->x2 - fo_window->x1 ) / 2 ); X fo_ycenter = fo_window->y1 + (( fo_window->y2 - fo_window->y1 ) / 2 ); X #ifdef OLD_DEBUG X fprintf( stderr, "screen is now drawn\n" ); #endif X X /*** Initialize error handler */ X X err_init(); X #ifdef OLD_DEBUG X fprintf( stderr, "error handler is now initialized\n" ); #endif X X sfsx( pr_file ); X X } X sfsx( program ) X char *program; X { X register int orbit; /* cycle through orbits */ X register int c; /* a multipurpose counter */ X int x_continue; /* continue main loop */ X long x_target; /* target time (met) for next display update */ X long x_next; /* next target time (to calculate rotation) */ X static struct sfs_orbit *sorbit_array[ ORBITS ]; X /* array of orbit structures */ X static int x_int; /* a dummy for initial setting of element */ X X /*** Set up dummy int pointer for elements */ X X x_elements = &x_int; X X /*** Allocate memory for Escape menu */ X X for ( c = 0; c < EM_TITLES; ++c ) X { X if ( ( em_titles[ c ] = malloc( 64 ) ) == NULL) X { X bw_error( MEMERR_ESC ); X } X } X #ifdef OLD_DEBUG X fprintf( stderr, "escape menu is now initialized\n" ); #endif X X /*** Send initializing message on status/help line */ X X sfsx_help( SFSX_INIT ); X X /*** Set up default values in case they are not read X by the program file. */ X X for ( orbit = 0; orbit < ORBITS; ++orbit ) X { X sorbit_array[ orbit ] = NULL; /* set all orbits to NULL */ X } X X sfs_tfactor = 1; /* default time factor = 1 (real time) */ X sfs_inc = 120; /* default display update = 120 X seconds (2 minutes) */ X sfs_insertion = 0; /* default insertion point = 0 seconds */ X X /*** Interpret the program file */ X X if ( sfs_pr( program, pr_name, sorbit_array, ORBITS ) == BW_ERROR ) X { X sprintf( sfsx_tbuf, SFSX_PRERR, program ); X bw_error( sfsx_tbuf ); X sfs_exit( ); X exit( 1 ); X } #ifdef OLD_DEBUG X else X { X sprintf( sfsx_tbuf, "Successfully interpreted program file <%s>", program ); X bw_debug( sfsx_tbuf ); X } #endif X X /*** Set up program screen */ X X cp_prog( program ); X X /*** Initialize displays */ X X di_init( sorbit_array, ORBITS, &x_displays, &n_displays, &t_array ); X X /*** Set initial elements to toggle */ X X x_elements = sfsx_curel(); X #ifdef OLD_DEBUG X for ( c = 0; c < n_displays; ++c ) X { X sprintf( sfsx_tbuf, "Display title %d: %s", c, t_array[ c ] ); X bw_debug( sfsx_tbuf ); X } #endif X X /*** find first visual display, and set zoom and upper windows to it */ X X c = 0; X x_continue = TRUE; X while( ( c < n_displays ) && ( x_continue == TRUE )) X { X if ( x_displays[ c ]->type == SFSD_VISUAL ) X { X d_zoom = c; X d_upper = c; X x_continue = FALSE; X } X ++c; X } X X /*** find first ground track display, and set lower window to it */ X X c = 0; X x_continue = TRUE; X while( ( c < n_displays ) && ( x_continue == TRUE )) X { X if ( x_displays[ c ]->type == SFSD_GROUND ) X { X d_lower = c; X x_continue = FALSE; X } X ++c; X } X X /*** Read spd files for all active orbits */ X X for ( c = 0; c < ORBITS; ++c ) X { X if ( sorbit_array[ c ] != NULL ) X { X X /* first read orb file for this orbit */ X X spj_readspd( sorbit_array[ c ]->orbfile, X &(sorbit_array[ c ]->o_start), &(sorbit_array[ c ]->o_end) ); X X /* read grid file for this orbit */ X X spj_readspd( sorbit_array[ c ]->gridfile, X &(sorbit_array[ c ]->g_start), &(sorbit_array[ c ]->g_end) ); X X /* read surface data file for this orbit */ X X spj_readspd( sorbit_array[ c ]->surfile, X &(sorbit_array[ c ]->s_start), &(sorbit_array[ c ]->s_end) ); X X /* read point data file for this orbit */ X #ifdef USEPOINTS X spj_readspd( sorbit_array[ c ]->pdfile, X &(sorbit_array[ c ]->p_start), &(sorbit_array[ c ]->p_end) ); #endif X X } X } X X /*** Send help message */ X X sfsx_help( SFSX_HELP ); X X /*** Initialize ground track and forward track for each orbit */ X X for ( orbit = 0; orbit < ORBITS; ++orbit ) X { X if ( sorbit_array[ orbit ] != NULL ) X { X X /*** Initialize ground track system */ X X gt_init( sorbit_array, orbit ); X X /*** Initialize the forward orbital track */ X X ft_init( sorbit_array, orbit, sfsx_poll ); X X } X } X X /*** Poll to allow early exit with escape key */ X X sfsx_poll(); X X x_target = sfsx_getmet(); /* initialize mission elapsed time */ X X /*** Main Program Loop */ X X x_continue = TRUE; X while( x_continue == TRUE ) X { X X /*** 1. See if a new focus and/or orbit needs to be set up */ X /*** This is a stub presently, but will eventually allow */ X /*** "true" space flight, i.e., the ability to switch to */ X /*** a transfer orbit, and eventually to another orbital */ X /*** focus. */ X X sfsx_poll(); X X /*** 2. Perform necessary calculations */ X /*** 2a. first calculate the current orbital positions X (subsatellite points) and update ground tracks */ X #ifdef OLD_DEBUG X sprintf( sfsx_tbuf, "[pr:] main(): orbit %d, focus %s, mass %le", X x_current, sorbit_array[ x_current ]->aorbit->focus->name, X sorbit_array[ x_current ]->aorbit->focus->mass ); X bw_debug( sfsx_tbuf ); #endif X X x_next = x_target + ( sfs_inc * sfs_tfactor ); X for ( orbit = 0; orbit < ORBITS; ++orbit ) X { X if ( sorbit_array[ orbit ] != NULL ) X { X or_ssp( sorbit_array[ orbit ]->aorbit, X x_target, &(sorbit_array[ orbit ]->ssp_lat), X &(sorbit_array[ orbit ]->ssp_lon), X &(sorbit_array[ orbit ]->ssp_r), X &(sorbit_array[ orbit ]->ssp_n) ); #ifdef OLD_DEBUG X sprintf( sfsx_tbuf, "main(): ssp, time %ld lat %.2lf lon %.2lf no %ld", X x_target, x_lat, x_lon, x_n ); X bw_debug( sfsx_tbuf ); #endif X sprintf( sfsx_tbuf, "Updating ground track, orbit %d", orbit + 1 ); X bw_message( sfsx_tbuf ); X gt_update( x_target, sorbit_array, ORBITS ); /* Update Ground Track */ #ifdef OLD_DEBUG X bw_debug( "return from gt_update()" ); #endif X sfsx_poll(); X X /*** 2b. calculate the next orbital position to allow X the rotation to be set appropriately */ X X or_ssp( sorbit_array[ orbit ]->aorbit, X x_next, &(sorbit_array[ orbit ]->nssp_lat), X &(sorbit_array[ orbit ]->nssp_lon), X &(sorbit_array[ orbit ]->nssp_r), X &(sorbit_array[ orbit ]->nssp_n) ); #ifdef OLD_DEBUG X sprintf( sfsx_tbuf, "main(): next ssp, lat %.2lf lon %.2lf", X nssp_lat, nssp_lon ); X bw_debug( sfsx_tbuf ); #endif X X sfsx_poll(); X X /*** 2c. calculate the rotation based on the current position X and the next position */ X X sorbit_array[ orbit ]->ssp_rot = X vi_rotate( sorbit_array[ orbit ]->ssp_lon, X sorbit_array[ orbit ]->ssp_lat, X sorbit_array[ orbit ]->nssp_lon, X sorbit_array[ orbit ]->nssp_lat ); X #ifdef OLD_DEBUG X sprintf( sfsx_tbuf, "main(): rotation = %.2lf deg", X x_rot ); X bw_debug( sfsx_tbuf ); #endif X X sfsx_poll(); X } X } X X /*** 2d. calculate perspective points */ X X pe_calc( sorbit_array, ORBITS, sfsx_poll ); X sfsx_poll(); X X /*** calculations for each orbit */ X X for ( orbit = 0; orbit < ORBITS; ++orbit ) X { X if ( sorbit_array[ orbit ] != NULL ) X { X X /*** 2d+. calculate forward track */ X X ft_calc( x_target, sorbit_array, orbit, sfsx_poll ); X X /*** 2e. calculate positions for the surface data */ X X sprintf( sfsx_tbuf, CALCSD, orbit + 1 ); X bw_message( sfsx_tbuf ); X spj_calc( &( sorbit_array[ orbit ]->s_start ), X &( sorbit_array[ orbit ]->s_end ), X sorbit_array[ orbit ]->ssp_lat, X sorbit_array[ orbit ]->ssp_lon, X (double) sorbit_array[ orbit ]->ssp_r, X sorbit_array[ orbit ]->aorbit->focus->radius, X sorbit_array[ orbit ]->ssp_rot, SPJ_ALLSIDES, sfsx_poll ); X sfsx_poll(); X X /*** 2f. calculate positions for the point data */ X #ifdef USEPOINTS X sprintf( sfsx_tbuf, "Calculating point data points for orbit %d", X orbit + 1 ); X bw_message( sfsx_tbuf ); X spj_calc( &( sorbit_array[ orbit ]->p_start ), X &( sorbit_array[ orbit ]->p_end ), X sorbit_array[ orbit ]->ssp_lat, X sorbit_array[ orbit ]->ssp_lon, X (double) sorbit_array[ orbit ]->ssp_r, X sorbit_array[ orbit ]->aorbit->focus->radius, X sorbit_array[ orbit ]->ssp_rot, SPJ_ALLSIDES, sfsx_poll ); X sfsx_poll(); #endif X X /*** 2g. calculate positions for the grid data */ X X sprintf( sfsx_tbuf, CALCGR, orbit + 1 ); X bw_message( sfsx_tbuf ); X spj_calc( &( sorbit_array[ orbit ]->g_start ), X &( sorbit_array[ orbit ]->g_end ), X sorbit_array[ orbit ]->ssp_lat, X sorbit_array[ orbit ]->ssp_lon, X (double) sorbit_array[ orbit ]->ssp_r, X sorbit_array[ orbit ]->aorbit->focus->radius, X sorbit_array[ orbit ]->ssp_rot, SPJ_ALLSIDES, sfsx_poll ); X sfsx_poll(); X X /*** 2h. calculate positions for the orb. Note that the X orb has to be shown from viewer latitude 0.0, X longitude 0.0 */ X X sprintf( sfsx_tbuf, CALCORB, orbit + 1 ); X bw_message( sfsx_tbuf ); X spj_calc( &( sorbit_array[ orbit ]->o_start ), X &( sorbit_array[ orbit ]->o_end ), X 0.0, 0.0, (double) sorbit_array[ orbit ]->ssp_r, X sorbit_array[ orbit ]->aorbit->focus->radius, X sorbit_array[ orbit ]->ssp_rot, SPJ_ALLSIDES, sfsx_poll ); X sfsx_poll(); X X } X } X X /*** 3. Wait until time for next display */ X X bw_message( SFSX_WAIT ); X sfsx_poll(); X while( sfsx_getmet() < x_target ) X { #ifdef OLD_DEBUG X sprintf( sfsx_tbuf, "wait: %ld / %ld", sfsx_getmet(), x_target ); X bw_message( sfsx_tbuf ); #endif X sfsx_poll(); X } X X /*** 4. Update the simulation display */ X #ifdef OLD_DEBUG X sprintf( sfsx_tbuf, "call update() display %d, n %d, orbit_n %ld", X x_display, ORBITS, x_n ); X bw_debug( sfsx_tbuf ); X sprintf( sfsx_tbuf, "call update() lat %.1lf lon %.1lf, rad %.1lf dis %.1lf", X x_lat, x_lon, X sorbit_array[ x_current ]->aorbit->focus->radius, X (double) x_r ); X bw_debug( sfsx_tbuf ); X sprintf( sfsx_tbuf, "call update() focal radius %.1lf", X sorbit_array[ 0 ]->aorbit->focus->radius ); X bw_debug( sfsx_tbuf ); X sfsx_test( x_display, ORBITS, x_lat, x_lon, X sorbit_array[ x_current ]->aorbit->focus->radius, X (double) x_r, x_n, sorbit_array ); #endif X X sfsx_update( ORBITS, X sorbit_array, x_displays, n_displays, x_target, X x_zoom, d_zoom, d_upper, d_lower ); X X /*** display is initialized */ X X x_init = TRUE; X X /*** 5. Set the next target time */ X X x_target += ( sfs_inc * sfs_tfactor ); X #ifdef BLOCKEDOUT X bw_message( "end of main loop cycle: ESCAPE to exit" ); X if ( kb_rx() == 0x1b ) X { X sfs_exit(); X } #endif X X } X X } X /**************************************************************** X X sfs_exit() Exit from Simulation Module X ****************************************************************/ X sfs_exit() X { /* gr_cls( GR_PRIMARY ); */ X if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != NULL ) X { X fprintf( data, "%s %s %s\n", SFSCH_MODEL, pr_file, SFS_CONTARG ); X fclose( data ); X } X else X { X fprintf( stderr, ERR_CHAIN ); X } X gr_deinit(); X exit( 0 ); X } X /**************************************************************** X X sfsx_colors() Initialize Colors for Simulation X ****************************************************************/ X sfsx_colors() X { X register int c; X int n; X X if ( gr_colors > 8 ) X { X cl_mback = WHITE; X cl_mfore = BLACK; X cl_marker = DARK_CYAN; X cl_grid = DARK_BLUE; X cl_surface = DARK_GREEN; X n = LIGHT_RED; X for ( c = 0; c < OR_COLORS; ++c ) X { X cl_orbits[ c ] = n; X ++n; X } X } X else if ( gr_colors > 2 ) X { X cl_mback = WHITE; X cl_mfore = BLACK; X cl_marker = BLACK; X cl_grid = WHITE; X cl_surface = WHITE; X for ( c = 0; c < OR_COLORS; ++c ) X { X cl_orbits[ c ] = WHITE; X } X } X else X { X cl_mback = WHITE; X cl_mfore = BLACK; X cl_marker = WHITE; X cl_grid = WHITE; X cl_surface = WHITE; X for ( c = 0; c < OR_COLORS; ++c ) X { X cl_orbits[ c ] = WHITE; X } X } X X } X /**************************************************************** X X sfsx_poll() X ****************************************************************/ X sfsx_poll() X { X register int c; X static int x, y, b; X X /* Check for keyboard input */ X X while ( kb_rxstat() == TRUE ) X { X c = kb_rx(); X if ( c == 0x1b ) X { X sfsx_esc(); X x_elements = sfsx_curel(); X } X else X { X el_toggle( c, x_elements ); X if ( x_init == TRUE ) X { X el_show( GR_PRIMARY, e_wind, *x_elements ); X } X } X } X X /* Check for mouse input */ X X if ( gr_ismouse == TRUE ) X { X if ( gr_mouse( SAMPLE, &x, &y, &b ) == TRUE ) X { X X gr_mouse( WAIT, &x, &y, &b ); /* click down */ X gr_mouse( WAIT, &x, &y, &b ); /* click up */ X #ifdef OLD_DEBUG X sprintf( sfsx_tbuf, "Mouse hit: %d %d", x, y ); X bw_debug( sfsx_tbuf ); #endif X X /* Is the release within bounds ? */ X X if ( uil_bounds( x, y, main_window->tbar_x1, main_window->tbar_y1, X main_window->tbar_x2, main_window->tbar_y2) == TRUE ) X { X sfsx_esc(); X } X X } X } X } X /**************************************************************** X X sfsx_esc() X ****************************************************************/ X sfsx_esc() X { X int c; X static struct menu_box esc_box; X int y, test; X static int x_x1 = 0, x_y1 = 0, x_x2 = 0, x_y2 = 0, item; X static int x_ebuf; X X ui_push(); /* save current ui screen */ X ui_setscreen( GR_PRIMARY ); /* set primary screen */ X if ( x_x1 == 0 ) X { X x_x1 = (int) fo_xcenter - ( ui_grwind->xmax / 4 ); X x_y1 = (int) fo_ycenter - ( ui_grwind->fysize * 7 ); X x_x2 = (int) fo_xcenter + ( ui_grwind->xmax / 4 ); X x_y2 = (int) fo_ycenter + ( ui_grwind->fysize * 5 ); X } X X strcpy( em_titles[ 0 ], ZOOMTITLE ); X strcpy( em_titles[ 1 ], UPPERTITLE ); X strcpy( em_titles[ 2 ], LOWERTITLE ); X strcpy( em_titles[ 3 ], SYSTITLE ); X strcpy( em_titles[ 4 ], ABORTTITLE ); X strcpy( em_titles[ 5 ], EXITTITLE ); X X gr_imsave( GR_PRIMARY, TRUE, x_x1, x_y1, x_x2, x_y2, &x_ebuf ); X X sfsx_help( SFSX_MM ); X X esc_box.is_drawn = FALSE; X item = ui_list( MENU_SLIDERS, x_x1, x_y1, x_x2, x_y2, X ESCTITLE, EM_TITLES, X em_titles, cl_mfore, cl_mback, cl_marker, X &esc_box ); X X gr_imsave( GR_PRIMARY, FALSE, x_x1, x_y1, x_x2, x_y2, &x_ebuf ); X gr_imfree( x_ebuf ); X sfsx_help( SFSX_HELP ); X X switch( item ) X { X case 0: X d_zoom = sdi( t_array, n_displays, ZOOMTITLE ); X x_zoom = TRUE; X break; X case 1: X d_upper = sdi( t_array, n_displays, UPPERTITLE ); X x_zoom = FALSE; X break; X case 2: X d_lower = sdi( t_array, n_displays, LOWERTITLE ); X x_zoom = FALSE; X break; X case 3: X ssp(); X break; X case 4: X if ( ( data = fopen( SFS_CHAINFN, "w" ) ) != NULL ) X { X fprintf( data, "%s\n", SFS_EXITARG ); X fclose( data ); X } X else X { X fprintf( stderr, ERR_CHAIN ); X } X gr_deinit(); X exit( 0 ); X break; #ifdef ABORT_ON_ESCAPE X case TK_EXIT: #endif X case 5: X sfs_exit(); X exit(0); X default: X break; X } X X ui_pop(); /* restore ui screen */ X X } X /**************************************************************** X X sfsx_getmet() Get Mission Elapsed Time X ****************************************************************/ X long sfsx_getmet() X { X static int x_initialized = FALSE; X static time_t x_now; X X if ( x_initialized == FALSE ) X { X x_initialized = TRUE; X x_now = time( NULL ); X sfsx_epoch = x_now; #ifdef OLD_DEBUG X sprintf( sfsx_tbuf, "sfs_getmet(): epoch = %ld", sfsx_epoch ); X bw_debug( sfsx_tbuf ); #endif X return (long) sfs_insertion; X } X X x_now = time( NULL ); X return (long) ( ( ( x_now + sfs_insertion ) - sfsx_epoch ) * sfs_tfactor ); X } X #ifdef OLD_DEBUG sfsx_test( display, n, lat, lon, radius, distance, orbit_n, sorbit_array ) SHAR_EOF true || echo 'restore of sfs/sfs/sfsx.c failed' fi echo 'End of part 20' echo 'File sfs/sfs/sfsx.c is continued in part 21' echo 21 > _shar_seq_.tmp exit 0 exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.